﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.DirectoryServices;

namespace ImageUploader.domain
{
    public class StaticMethods
    {

        public static bool IsUserCriticalToAD(DirectoryEntry de)
        {
            return (de.Properties["IsCriticalSystemObject"].Count > 0 && (bool)(de.Properties["IsCriticalSystemObject"][0]));
        }

        public static bool DirectoryEntryListContainsDE(List<DirectoryEntry> list, DirectoryEntry de)
        { 
            
            foreach(DirectoryEntry deInList in list)
                if(deInList.Properties["cn"][0].Equals(de.Properties["cn"][0]))
                    return true;

            return false;
        }

        public static void ExecuteMethodShowLoading(MethodInvoker method,Form f)
        {
            f.Cursor = Cursors.WaitCursor;
            try
            {
                method();
            }
            finally
            {
                f.Cursor = Cursors.Default;
            }
        }
    }
}
